-- @owner:yangjian
-- @date:2024-4-1
-- @testpoint:1.去除大对象使用限制，测试lo_from_bytea函数使用和参数的表现，合理报错

--清理环境
CREATE OR REPLACE FUNCTION f_opengauss_large_object_function_case0017_1()  
RETURNS VOID AS 
$$
BEGIN  
    BEGIN
    PERFORM lo_unlink(100);
    EXCEPTION
        WHEN others THEN
            NULL;
    end;
	BEGIN
    PERFORM lo_unlink(-2147483648);
    EXCEPTION
        WHEN others THEN
            NULL;
    end;
	BEGIN
    PERFORM lo_unlink(4294967295);
    EXCEPTION
        WHEN others THEN
            NULL;
    end;
	BEGIN
    PERFORM lo_unlink(-1);
    EXCEPTION
        WHEN others THEN
            NULL;
    end;
	BEGIN
    PERFORM lo_unlink(200);
    EXCEPTION
        WHEN others THEN
            NULL;
    end;
	BEGIN
    PERFORM lo_unlink(201);
    EXCEPTION
        WHEN others THEN
            NULL;
    end;
	BEGIN
    PERFORM lo_unlink(202);
    EXCEPTION
        WHEN others THEN
            NULL;
    end;
END;  
$$
LANGUAGE plpgsql;
/

select f_opengauss_large_object_function_case0017_1();

--环境准备
drop table if exists t_opengauss_large_object_function_case0017_1 cascade;
CREATE TABLE t_opengauss_large_object_function_case0017_1 (loid oid,fd int);
INSERT INTO t_opengauss_large_object_function_case0017_1 (loid) SELECT lo_create(100);

--step1:测试loid参数为不存在值;expect:成功
select lo_from_bytea(200,'aaaaaa');

--step2:测试loid参数为存在值;expect:失败
select lo_from_bytea(100,'aaaaaa');

--step3:测试loid参数为非int类型;expect:失败
select lo_from_bytea('a','aaaaaa');

--step4:测试loid参数为负数;expect:成功
INSERT INTO t_opengauss_large_object_function_case0017_1 (loid) select lo_from_bytea(-1,'aaaaaa');

--step5:测试loid参数为空值;expect:成功
select lo_from_bytea(null,'aaaaaa');

--step6:测试loid参数超过oid边界值;expect:失败
select lo_from_bytea(4294967296,'aaaaaa');
select lo_from_bytea(-2147483649,'aaaaaa');

--step7:测试loid参数为oid边界值;expect:成功
select lo_from_bytea(-2147483648,'aaaaaa');

--step8:测试loid参数为空串;expect:成功
select lo_from_bytea('','aaaaaa');

--step9:测试loid参数为0;expect:成功
INSERT INTO t_opengauss_large_object_function_case0017_1 (loid) select lo_from_bytea(0,'aaaaaa');

--step10:测试date参数为非bytea类型;expect:失败
select lo_from_bytea(201,1);

--step11:测试date参数含中文;expect:成功
select lo_from_bytea(202,'测试');

--清理环境
select lo_unlink(loid) from t_opengauss_large_object_function_case0017_1;
select f_opengauss_large_object_function_case0017_1();
drop table if exists t_opengauss_large_object_function_case0017_1 cascade;
drop function f_opengauss_large_object_function_case0017_1();
